package net.tv90.bfmccore.util.vector;

import java.io.Serializable;

/**
 * 二维整形向量
 */

public class Vector2i implements Serializable {

    public int x, y;

    public Vector2i() {
        set(0, 0);
    }

    public Vector2i(int x, int y) {
        set(x, y);
    }

    public void set(int x, int y) {
        this.x = x;
        this.y = y;
    }

    /**
     * 获取长度
     *
     * @return 长度
     */
    public int lengthSquared() {
        return x * x + y * y;
    }

    /**
     * 平移向量
     *
     * @param x x平移量
     * @param y y平移量
     * @return this
     */
    public Vector2i translate(int x, int y) {
        this.x += x;
        this.y += y;
        return this;
    }

    @Override
    public String toString() {
        return "Vector2i[" + x + ", " + y + ']';
    }

    public int getX() {
        return this.x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return this.y;
    }

    public void setY(int y) {
        this.y = y;
    }

}